package com.hengpeng.msls.service;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import com.hengpeng.itfinbase.persist.AccountLog;
import com.hengpeng.itfinbase.persist.Message;
import com.hengpeng.msls.port.PortFactory;
import com.hengpeng.msls.port.client.vo.client.AccountTransType;
import com.hengpeng.msls.port.client.vo.client.Letter;
import com.hengpeng.msls.port.client.vo.client.TradeMode;

public class BaseService
{
	@Autowired
	protected ServiceFactory serviceFactory;

	@Autowired
	@Qualifier("portFactoryImpl")
	protected PortFactory portFactory;

	protected final Log logger = LogFactory.getLog(this.getClass());

	/**
	 * 将数据库查回的实体Message的list转换成对应vo的list
	 * @param list
	 * @return
	 */
	public List<Letter> conversMessageListToListVo(List<Message> list)
	{
		List<Letter> retList = new ArrayList<Letter>();
		for (Message message : list)
		{
			retList.add(conversMessageToVo(message));
		}
		return retList;
	}

	/**
	 * 将数据库查回的实体Message转换成对应的vo
	 * @param list
	 * @return
	 */
	public Letter conversMessageToVo(Message message)
	{
		Letter letter = new Letter();
		letter.setContent(message.getContent());
		// letter.setSendTime(message.getSendTime());
		letter.setTitle(message.getTitle());
		// letter.setType(MessageType.valueOf(message.getType().name()));
		return letter;
	}

	/**
	 * 将数据库查回的实体AccountLog的list转换成对应vo的list
	 * @param list
	 * @return
	 */
	public List<com.hengpeng.msls.port.client.vo.client.AccountLog> conversAccounLogListToListVo(List<AccountLog> list)
	{
		List<com.hengpeng.msls.port.client.vo.client.AccountLog> logList = new ArrayList<com.hengpeng.msls.port.client.vo.client.AccountLog>();
		for (AccountLog accountLog : list)
		{
			logList.add(conversAccounLogToVo(accountLog));
		}
		return logList;
	}

	/**
	 * 将数据库查回的实体AccountLog转换成对应的vo
	 * @param list
	 * @return
	 */
	public com.hengpeng.msls.port.client.vo.client.AccountLog conversAccounLogToVo(AccountLog accountLog)
	{

		com.hengpeng.msls.port.client.vo.client.AccountLog log = new com.hengpeng.msls.port.client.vo.client.AccountLog();
		log.setRemnantMoney(accountLog.getRemnantBaseMoney());
		log.setTransType(AccountTransType.valueOf(accountLog.getTransType().name()));
		log.setTradeMode(TradeMode.valueOf(accountLog.getTradeMode().name()));
		log.setMoney(accountLog.getMoney());
		log.setTransTime(accountLog.getTransTime());
		log.setRemnantMoney(accountLog.getRemnantBaseMoney());
		log.setRemnantFreezeMoney(accountLog.getRemnantFreezeMoney());
		log.setReferenceId(accountLog.getReferenceId());
		log.setRemark(accountLog.getRemark());
		return log;
	}

}
